/*
 * @Author: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @Date: 2025-10-12 16:22:26
 * @LastEditors: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @LastEditTime: 2025-10-12 21:33:08
 * @FilePath: /GateServer/src/util/httpresponsebuilder.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "httpresponsebuilder.h"
#include "util.h"
#include <boost/beast/core/ostream.hpp>
#include <boost/beast/http/field.hpp>
#include <jsoncpp/json/value.h>

namespace Yizhi {
     void HttpResponseBuilder::buildSuccessResponse(http::response<http::dynamic_body>& response, const Json::Value &data){
        auto res=data.toStyledString();
        boost::beast::ostream(response.body())<<res;

    }
    void HttpResponseBuilder::buildJosnParseErrorResponse(http::response<http::dynamic_body>& response){
        buildErrorResponse(response,Ecode::JSONFLASE,"json parse error");
    }
    void HttpResponseBuilder::buildErrorResponse(http::response<http::dynamic_body>& response, Ecode code, const std::string &message){
        Json::Value root;
        root["error"]=code;
        if(!message.empty()){
            root["msg"]=message;
        }
        auto res=root.toStyledString();
        boost::beast::ostream(response.body())<<res;
    }
}